package com.universest.swordholder.task

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.takeWhile

class DirectTask<A,B>(name: String = "", val desc: String = "", private val obj:B) : AbstractTask<A,B>(name) {

    override suspend fun call(param:A): B {
        return obj;
    }

    override val progress: Flow<Pair<Int, Int>> = flow {
        emit(0 to 1)
        end.takeWhile { !it }.collect {  }
        emit(1 to 1)
    }
    override val message: Flow<String> = flow { emit(desc) }
}